package xmlsync2;
import java.util.LinkedList;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * @author jinwoo
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Query
{
	private String text;
	private LinkedList params;
	public Query(final String text, final NodeList list)
	{
		params = new LinkedList();
		this.text = text.trim();
		for (int i =0; i < list.getLength(); i++)
		{
			String name = ((Element)list.item(i)).getAttribute("name");
			if (name.length()>0)
				params.addLast(name);
		}
	}
	public String querystring(final LinkedList params)
	{
		String querystring = text;
		for (int i=0; i<this.params.size(); i++)
			if (i<params.size())
				querystring = Str.replace(querystring, '@'+(String)this.params.get(i), (String)params.get(i));
		return querystring;
	}
}
